home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / resourcecollection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-07-23  |  5.1 KB  |  93 lines

  1. /*
  2.  For general Scribus (>=1.3.2) copyright and licensing information please refer
  3.  to the COPYING file provided with the program. Following this notice may exist
  4.  a copyright and/or license notice that predates the release of Scribus 1.3.2
  5.  for which a new license (GPL+exception) is in place.
  6.  */
  7. /***************************************************************************
  8. *                                                                         *
  9. *   This program is free software; you can redistribute it and/or modify  *
  10. *   it under the terms of the GNU General Public License as published by  *
  11. *   the Free Software Foundation; either version 2 of the License, or     *
  12. *   (at your option) any later version.                                   *
  13. *                                                                         *
  14. ***************************************************************************/
  15.  
  16.  
  17. #ifndef RESOURCE_COLLECTION_H
  18. #define RESOURCE_COLLECTION_H
  19.  
  20. #include <QList>
  21. #include <QMap>
  22. #include <QString>
  23.  
  24. /** 
  25. *   A simple structure which holds the names of all resources & styles used in a doc or part of a document.
  26. *   Also holds pointers to the doc's fontset and colorset.
  27. *   The names are stored as a QMap<QString,QString>. When a doc is queried for it's used resources, these
  28. *   maps get an entry  (nam -> nam) for each used resource 'nam'. You can replace resources consistently by
  29. *   changing these maps and asking the doc to use the altered maps to change all old names to the new one.
  30. *   Operations:
  31. *   - getNamedResources(ResourceCollection& rsc)              ... fills 'rsc' with identity mappings for used resources
  32. *   - replaceNamedResources(const ResourceCollection& maps)   ... uses 'maps' to change old names to new names
  33. *   - redefineNamedResources(const ResourceCollection& defs)  ... uses the definitions in 'defs' to overwrite/add resources
  34. *   - makeNamedResourcesUnique(ResourceCollection& other)     ... changes mapping in 'other' to unique names
  35. *   Merge options:  keep old def, keep new def, rename new resource to unique name
  36. */
  37. class ResourceCollection
  38. {
  39. public:
  40.     void collectFont(const QString& name)      { if (!name.isEmpty()) m_fonts.insert(name,name); }
  41.     void collectPattern(const QString& name)   { if (!name.isEmpty()) m_patterns.insert(name,name); }
  42.     void collectColor(const QString& name)     { if (!name.isEmpty()) m_colors.insert(name,name); }
  43.     void collectStyle(const QString& name)     { if (!name.isEmpty()) m_pstyles.insert(name,name); }
  44.     void collectCharStyle(const QString& name) { if (!name.isEmpty()) m_cstyles.insert(name,name); }
  45.     void collectLineStyle(const QString& name) { if (!name.isEmpty()) m_linestyles.insert(name,name); }
  46.     
  47.     void mapFont(const QString& oldname, const QString& newname)      { m_fonts.insert(oldname, newname); }
  48.     void mapPattern(const QString& oldname, const QString& newname)   { m_patterns.insert(oldname, newname); }
  49.     void mapColor(const QString& oldname, const QString& newname)     { m_colors.insert(oldname, newname); }
  50.     void mapStyle(const QString& oldname, const QString& newname)     { m_pstyles.insert(oldname, newname); }
  51.     void mapCharStyle(const QString& oldname, const QString& newname) { m_cstyles.insert(oldname, newname); }
  52.     void mapLineStyle(const QString& oldname, const QString& newname) { m_linestyles.insert(oldname, newname); }
  53.     
  54.     void mapFonts(const QMap<QString,QString>& newnames)      { m_fonts = newnames; }
  55.     void mapPatterns(const QMap<QString,QString>& newnames)   { m_patterns = newnames; }
  56.     void mapColors(const QMap<QString,QString>& newnames)     { m_colors = newnames; }
  57.     void mapStyles(const QMap<QString,QString>& newnames)     { m_pstyles = newnames; }
  58.     void mapCharStyles(const QMap<QString,QString>& newnames) { m_cstyles = newnames; }
  59.     void mapLineStyles(const QMap<QString,QString>& newnames) { m_linestyles = newnames; }
  60.     
  61.     const QMap<QString, QString>& fonts()      { return m_fonts; }
  62.     const QMap<QString, QString>& patterns()   { return m_patterns; }
  63.     const QMap<QString, QString>& colors()     { return m_colors; }
  64.     const QMap<QString, QString>& styles()     { return m_pstyles; }
  65.     const QMap<QString, QString>& charStyles() { return m_cstyles; }
  66.     const QMap<QString, QString>& lineStyles() { return m_linestyles; }
  67.     
  68.     QList<QString> fontNames() const      { return m_fonts.keys(); }
  69.     QList<QString> patternNames() const   { return m_patterns.keys(); }
  70.     QList<QString> colorNames() const     { return m_colors.keys(); }
  71.     QList<QString> styleNames() const     { return m_pstyles.keys(); }
  72.     QList<QString> charStyleNames() const { return m_cstyles.keys(); }
  73.     QList<QString> lineStyleNames() const { return m_linestyles.keys(); }
  74.  
  75.     // modifies newNames so that forall x in both newNames.key() and in existingNames, newNames[x] will map to a new unique name
  76.     static void makeUnique(QMap<QString,QString>& newNames, const QList<QString> existingNames);
  77.  
  78.     void makeNamedResourcesUnique(ResourceCollection& other);
  79.     
  80.     SCFonts* availableFonts;
  81.     ColorList* availableColors;
  82. private:
  83.     QMap<QString,QString> m_fonts;
  84.     QMap<QString,QString> m_patterns;
  85.     QMap<QString,QString> m_colors;
  86.     QMap<QString,QString> m_pstyles;
  87.     QMap<QString,QString> m_cstyles;
  88.     QMap<QString,QString> m_linestyles;
  89. };
  90.  
  91.  
  92. #endif
  93.